﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MachineLearning {
    abstract class SquashingFunction {

        protected string _name = null;
        public string Name {
            get { return _name; }
            set { _name = value; }
        }

        //the squashed output of the function
        public abstract double squash(double x);
        //the first derivitave of the function 
        public abstract double squashPrime(double x);

    }

    class Sigmoid : SquashingFunction {
        public Sigmoid() {
            _name = "sigmoid";
        }

        public override double squash(double x) {
            return 1.0 / (1.0 + Math.Pow(Math.E, -1.0 * x));
        }

        public override double squashPrime(double x) {
            return x * (1.0 - x);
        }
    }

    class Tanh : SquashingFunction {
        public Tanh() {
            _name = "tanh";
        }

        public override double squash(double x) {
            return (Math.Pow(Math.E, 2.0 * x) - 1.0) / (Math.Pow(Math.E, 2.0 * x) + 1.0);
        }

        public override double squashPrime(double x) {
            return 1.0 - Math.Pow(x, 2.0);
        }
    }

}
